import java.awt.print.Book;
import java.util.*;
class AuthenticationManager {
    Map<String,Integer> map;
    int Time;
    public AuthenticationManager(int timeToLive) {
        this.Time=timeToLive;
        map=new HashMap<>();
    }

    public void generate(String tokenId, int currentTime) {
        map.put(tokenId,currentTime);
    }

    public void renew(String tokenId, int currentTime) {
        if(map.containsKey(tokenId)){
            int time=map.get(tokenId);
            if(currentTime-time<Time){
                map.put(tokenId,currentTime);
            }
        }
    }

    public int countUnexpiredTokens(int currentTime) {
        int ret=0;
        for(Map.Entry<String,Integer> entry:map.entrySet()){
            if(currentTime-entry.getValue()<Time){
                ret++;
            }
        }
        return ret;
    }
}


















public class project {
    public long maxAlternatingSum(int[] nums) {
        int len=nums.length;
        long prev=0;
        long ret=0;
        for(int i=0;i<nums.length;i++){
            if(nums[i]>prev){
                ret+=nums[i]-prev;
            }
            prev=nums[i];
        }
        return ret;
    }
















    public int findMin(int[] nums) {
        int left=0;
        int right=nums.length-1;
        while (left<right){
            int mid=left+(right-left)/2;
            if(nums[mid]<nums[right]){
                right=mid;
            }else{
                left=mid+1;
            }
        }
        return nums[left];
    }


















//    public static void main(String[] args) {
//        String[] queries={"FooBar","FooBarTest","FootBall","FrameBuffer","ForceFeedBack"};
//        String pattern="FB";
//        System.out.println(camelMatch(queries,pattern));
//    }
    public List<Boolean> camelMatch(String[] queries, String pattern) {
        List<Boolean> list=new ArrayList<>();
        Stack<Character> stack=new Stack<>();
        for(int i=pattern.length()-1;i>=0;i--){
            char ch=pattern.charAt(i);
            stack.add(ch);
        }
        for(int i=0;i<queries.length;i++){
            String str=queries[i];
            boolean flag=true;
            for(char ch:str.toCharArray()){
                if(!stack.isEmpty()&&ch==stack.peek()){
                    stack.pop();
                }else{
                    if(ch>='A'&&ch<='Z'){
                        flag=false;
                        break;
                    }
                }
            }
            if(!stack.isEmpty()){
                flag=false;
            }
            stack=new Stack<>();
            for(int j=pattern.length()-1;j>=0;j--){
                char ch=pattern.charAt(j);
                stack.add(ch);
            }
            list.add(flag);
        }
        return list;
    }

















    public String longestWord(String[] words) {
        Set<String> set=new HashSet<>();
        String ans="";
        for(String word:words){
            set.add(word);
        }
        for(String s:set){
            if(s.length()>ans.length()||s.length()==ans.length()&&s.compareTo(ans)<0){
                boolean bool=true;
                for(int i=1;i<s.length();i++){
                    if(!set.contains(s.substring(0,i))){
                        bool=false;
                        break;
                    }
                }
                if(bool){
                    ans=s;
                }
            }
        }
        return ans;
    }
}
